-- StartMenu
-- 开始界面
StartMenu = class()

function StartMenu:init()
    self.m = false
    self.set = Setting()
    self.make = Maker()
    self.choose = Choose()
    self.lang = LanguageChanger()
    pushStyle()
    self.playButton = STButton(WIDTH / 2,HEIGHT / 3 + 120,LP.play,"Project:GB","Project:G")
    self.playButton.color = color(255, 255, 255, 255)
    self.playButton.width = 400
    self.playButton.height = 52*300/220
    self.playButton.clicked = function() self.choose:choice()  end
    
    self.exit = STButton(WIDTH / 2,HEIGHT / 3 - 60,LP.exit,"Project:RB","Project:G")
    self.exit.width = 400
    self.exit.height = 52*300/220
    self.exit.clicked = function() close() saveSetting() end
    
    self.settings = STButton(WIDTH / 2+42.5,HEIGHT / 3 + 30,LP.setting,"Project:GB","Project:G")
    self.settings.width = 400-52*300/220-15
    self.settings.height = 52*300/220
    self.settings.clicked = function() self.set:show() sound("Game Sounds One:Jump")  end

    self.language = STButton(WIDTH/2-164,HEIGHT/3+30,_,"Project:lang","Project:lang")
    self.language.width = 52*300/220
    self.language.clicked = function() self.lang:show() end
    
    self.height = 52*300/220
    self.maker = TextButton(75,40 ,"TC Studio\n"..Version)
    self.maker:setFont("HelveticaNeue-Light",30)
    self.maker.clicked = function() self.make:show() end
    self.maker.backColor = color(0, 26, 251, 0)
    self.maker.textColor = color(255,255,255,255)
    popStyle()
end

function StartMenu:draw()
    pushMatrix()
    pushStyle()
    textMode(CENTER)
    translate(self.lang.nx + self.set.xOffset - WIDTH,self.choose.yOffset - HEIGHT)
    
    background(43, 164, 218, 255)
    fill(255, 255, 255, 255)
    fontSize(100)
    text("PhysicsBox",WIDTH/2,HEIGHT/2+200)
    sprite("Project:MadeWithCodea",WIDTH-100,30,180)
    pushStyle()
    self.playButton:draw()
    self.settings:draw()
    self.maker:draw()
    self.exit:draw()
    self.language:draw()
    popStyle()
    popStyle()
    pushStyle()
    tint(255, 255, 255, 255 - ElapsedTime^10)
    sprite("Project:TC Icon",WIDTH/2,HEIGHT/2)
    popStyle()
    popMatrix()
    if self.choose.showing == true then
        self.choose:draw()
    elseif self.set.showing == true then
        self.set:draw()
    elseif self.make.showing == true then
        self.make:draw()
    elseif self.lang.showing == true then
        self.lang:draw()
    end
end

function StartMenu:touched(touch)
    if self.set.showing == true then
        self.set:touched(touch)
    elseif self.make.showing == true then
        self.make:touched(touch)
    elseif self.choose.showing == true then
        self.choose:touched(touch)
    elseif self.lang.showing == true then
        self.lang:touched(touch)  
    else
        self.playButton:touched(touch)
        self.settings:touched(touch)
        self.exit:touched(touch)
        self.maker:touched(touch)
        self.language:touched(touch)
    end
end

